﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;

namespace FunctionalCLR.Shell.Function {
    public class SumNode : FuncNode {
        
        public SumNode()
            : base() {
            base.Value = "sum";
            this.ParameterCount = 1;
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            double sum = 0;
            foreach (Node c in Children) {
                sum += Convert.ToDouble(c.Value);
            }

            return sum.ToString();
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }
    }
}
